package com.algo.panelmn;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

public class UuidWritable implements WritableComparable<UuidWritable> {
    private String uuid;
    private long time;

    public void set(String uuid, long time) {
    	this.uuid = uuid;
        this.time = time;
    }
    public String getUuid() {
        return uuid;
    }
    public long getTime() {
        return time;
    }
    public void write(DataOutput out) throws IOException {
    	out.writeUTF(uuid);
    	out.writeLong(time);
    }
    public void readFields(DataInput in) throws IOException {
    	uuid = in.readUTF();
    	time = in.readLong();
    }
	public int compareTo(UuidWritable o) {
		if(o == null)	return 1;
		if(uuid == null || o.uuid == null) {System.out.println("uuid null");return 1;}
		return uuid.compareTo(o.uuid);
	}
	public int compareTimeTo(UuidWritable o) {
		if(o == null)	return 1;
		if(time > o.time) return 1;
		else if(time < o.time) return -1;
		else return 0;
	}
	public String toString(){
		return uuid + ":" + time;
	}
	public int hashCode(){
		return uuid.hashCode();
	}
}